<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>PREPARE</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REV="MADE"
HREF="mailto:pgsql-docs@postgresql.org"><LINK
REL="HOME"
TITLE="PostgreSQL 9.1.2 Documentation"
HREF="index.html"><LINK
REL="UP"
TITLE="Embedded SQL Commands"
HREF="ecpg-sql-commands.html"><LINK
REL="PREVIOUS"
TITLE="OPEN"
HREF="ecpg-sql-open.html"><LINK
REL="NEXT"
TITLE="SET AUTOCOMMIT"
HREF="ecpg-sql-set-autocommit.html"><LINK
REL="STYLESHEET"
TYPE="text/css"
HREF="stylesheet.css"><META
HTTP-EQUIV="Content-Type"
CONTENT="text/html; charset=ISO-8859-1"><META
NAME="creation"
CONTENT="2011-12-01T22:07:59"></HEAD
><BODY
CLASS="REFENTRY"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="5"
ALIGN="center"
VALIGN="bottom"
><A
HREF="index.html"
>PostgreSQL 9.1.2 Documentation</A
></TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
TITLE="OPEN"
HREF="ecpg-sql-open.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
HREF="ecpg-sql-commands.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="60%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="20%"
ALIGN="right"
VALIGN="top"
><A
TITLE="SET AUTOCOMMIT"
HREF="ecpg-sql-set-autocommit.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="ECPG-SQL-PREPARE"
></A
>PREPARE</H1
><DIV
CLASS="REFNAMEDIV"
><A
NAME="AEN43410"
></A
><H2
>Name</H2
>PREPARE&nbsp;--&nbsp;prepare a statement for execution</DIV
><DIV
CLASS="REFSYNOPSISDIV"
><A
NAME="AEN43413"
></A
><H2
>Synopsis</H2
><PRE
CLASS="SYNOPSIS"
>PREPARE <TT
CLASS="REPLACEABLE"
><I
>name</I
></TT
> FROM <TT
CLASS="REPLACEABLE"
><I
>string</I
></TT
></PRE
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN43417"
></A
><H2
>Description</H2
><P
>     <TT
CLASS="COMMAND"
>PREPARE</TT
> prepares a statement dynamically
     specified as a string for execution.  This is different from the
     direct SQL statement <A
HREF="sql-prepare.html"
>PREPARE</A
>, which can also
     be used in embedded programs.  The <A
HREF="sql-execute.html"
>EXECUTE</A
>
     command is used to execute either kind of prepared statement.
    </P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN43423"
></A
><H2
>Parameters</H2
><P
></P
><DIV
CLASS="VARIABLELIST"
><DL
><DT
><TT
CLASS="REPLACEABLE"
><I
>prepared_name</I
></TT
></DT
><DD
><P
>        An identifier for the prepared query.
       </P
></DD
><DT
><TT
CLASS="REPLACEABLE"
><I
>string</I
></TT
></DT
><DD
><P
>        A literal C string or a host variable containing a preparable
        statement, one of the SELECT, INSERT, UPDATE, or
        DELETE.
       </P
></DD
></DL
></DIV
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN43436"
></A
><H2
>Examples</H2
><PRE
CLASS="PROGRAMLISTING"
>char *stmt = "SELECT * FROM test1 WHERE a = ? AND b = ?";

EXEC SQL ALLOCATE DESCRIPTOR outdesc;
EXEC SQL PREPARE foo FROM :stmt;

EXEC SQL EXECUTE foo USING SQL DESCRIPTOR indesc INTO SQL DESCRIPTOR outdesc;</PRE
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN43439"
></A
><H2
>Compatibility</H2
><P
>     <TT
CLASS="COMMAND"
>PREPARE</TT
> is specified in the SQL standard.
    </P
></DIV
><DIV
CLASS="REFSECT1"
><A
NAME="AEN43443"
></A
><H2
>See Also</H2
><A
HREF="sql-execute.html"
>EXECUTE</A
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="ecpg-sql-open.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="ecpg-sql-set-autocommit.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>OPEN</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ecpg-sql-commands.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>SET AUTOCOMMIT</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>